/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package code;

/**
 *
 * @author Catarina
 */
import java.io.*;
import java.util.*;


public class LerFicheiro {

    public static Rede importUsers(String file) throws IOException {
        //TreeMap<String, User> uts = new TreeMap<String, User>();
        
        Rede r = new Rede();
        String linha;
        int nusers = 0;
        int i = 0;
        String users[] = new String[4];
        
        Scanner input = new Scanner(System.in);
        System.out.println("Quantos registos pretende ler do ficheiro?\n");
        int counter = input.nextInt();

        BufferedReader in = new BufferedReader(new FileReader(file));

        for(linha = in.readLine(); linha != null && i < counter; i++){
            users = linha.split("\t");
            User u = new User(users[0], users[1], users[2], users[3]);
            r.addUser(u);
            nusers++;
            linha = in.readLine();
        }

        System.out.println(nusers + " Utilizadores adicionados");
        return r;
    }

    public static Rede importFriends(String file,Rede r) throws IOException {
        
        BufferedReader in = new BufferedReader(new FileReader(file));
        
        String linha;
        int nfriends = 0;
        String friends[] = new String[2];
        User friend1 = null, friend2;

        linha = in.readLine();
        while(linha != null) {
            friends = linha.split(", ");
            friend1 = r.searchUsersNick(friends[0]);
            friend2 = r.searchUsersNick(friends[1]);
            if (friend1 != null && friend2!= null) {
                r.addAmizade(friend1,friend2);
                nfriends++;
            }
            linha = in.readLine();
        }
        System.out.println(nfriends + " Amizades criadas");

        return r;
    }
}



